package com.longge;

import java.util.stream.IntStream;

/**
 * @program: my-code
 * @description:
 * @author: longge
 * @create: 2021-05-18 16:20
 */
public class CanPartition {

    public boolean canPartition(int[] nums) {

        int sum = IntStream.of(nums).sum();
        if (sum % 2 == 1) return false;
        int bp = sum / 2;
        int n = nums.length + 1;
        boolean[] dp = new boolean[bp + 1];
        dp[0] = true;
        for (int i = 1; i < n; i++) {
            for (int j = bp; j > 0; j--) {
                if (j - nums[i - 1] >= 0) {
                    dp[j] = dp[j] | dp[j - nums[i - 1]];
                }
            }
        }
        return dp[bp];
    }


}
